package com.ruoyi.project.file.detail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.file.detail.domain.FileDetail;
import com.ruoyi.project.file.detail.service.IFileDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 文件记录Controller
 * 
 * @author zhangqidi
 * @date 2025-08-06
 */
@Controller
@RequestMapping("/file/detail")
public class FileDetailController extends BaseController
{
    private String prefix = "file/detail";

    @Autowired
    private IFileDetailService fileDetailService;

    @RequiresPermissions("file:detail:view")
    @GetMapping()
    public String detail()
    {
        return prefix + "/detail";
    }

    /**
     * 查询文件记录列表
     */
    @RequiresPermissions("file:detail:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FileDetail fileDetail)
    {
        startPage();
        List<FileDetail> list = fileDetailService.selectFileDetailList(fileDetail);
        return getDataTable(list);
    }

    /**
     * 导出文件记录列表
     */
    @RequiresPermissions("file:detail:export")
    @Log(title = "文件记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FileDetail fileDetail)
    {
        List<FileDetail> list = fileDetailService.selectFileDetailList(fileDetail);
        ExcelUtil<FileDetail> util = new ExcelUtil<FileDetail>(FileDetail.class);
        return util.exportExcel(list, "文件记录数据");
    }

    /**
     * 新增文件记录
     */
    @RequiresPermissions("file:detail:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文件记录
     */
    @RequiresPermissions("file:detail:add")
    @Log(title = "文件记录", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FileDetail fileDetail)
    {
        return toAjax(fileDetailService.insertFileDetail(fileDetail));
    }

    /**
     * 修改文件记录
     */
    @RequiresPermissions("file:detail:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        FileDetail fileDetail = fileDetailService.selectFileDetailById(id);
        mmap.put("fileDetail", fileDetail);
        return prefix + "/edit";
    }

    /**
     * 修改保存文件记录
     */
    @RequiresPermissions("file:detail:edit")
    @Log(title = "文件记录", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FileDetail fileDetail)
    {
        return toAjax(fileDetailService.updateFileDetail(fileDetail));
    }

    /**
     * 删除文件记录
     */
    @RequiresPermissions("file:detail:remove")
    @Log(title = "文件记录", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(fileDetailService.deleteFileDetailByIds(ids));
    }
}
